package com.iocollege.tinyframe.mapper.system;

import com.iocollege.tinyframe.entity.system.SysPost;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 岗位信息表 Mapper 接口
 * </p>
 *
 * @author 关注公众号：MarkerHub
 * @since 2021-04-10
 */
public interface SysPostMapper extends BaseMapper<SysPost> {


    /**
     * 根据用户ID获取岗位选择框列表
     *
     * @param userId 用户ID
     * @return 选中岗位ID列表
     */
    @Select("select p.id\n" +
            "        from sys_post p\n" +
            "\t        left join sys_user_post up on up.post_id = p.id\n" +
            "\t        left join sys_user u on u.id = up.user_id\n" +
            "\t    where u.id = #{userId}")
    public List<Integer> selectPostListByUserId(Long userId);


    /**
     * 查询用户所属岗位组
     *
     * @param userName 用户名
     * @return 结果
     */
    @Select("select p.id, p.post_name, p.post_code\n" +
            "\t\tfrom sys_post p\n" +
            "\t\t\t left join sys_user_post up on up.post_id = p.id\n" +
            "\t\t\t left join sys_user u on u.id = up.user_id\n" +
            "\t\twhere u.user_name = #{userName}")
    public List<SysPost> selectPostsByUserName(String userName);
}
